﻿using System;
using System.Web;
using Services.Abstract;

namespace Web
{
    public partial class Login : BasePage
    {
        public IUserService UserService { get; set; }

        protected new void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.Redirect("/");
            }
        }

        protected void BtnLogin_OnClick(object sender, EventArgs e)
        {
            string login = TbLogin.Text;
            string password = TbPassword.Text;

            try
            {
                UserService.SignIn(login, password, false);

                Response.Redirect(Request.QueryString["FromUrl"] ?? "/Profile.aspx");
            }
            catch (Exception ex)
            {
                ShowFormError(LoginFormError.ClientID, ex.Message);
            }
        }
    }
}